<?php if ( ! defined('BASEPATH')) exit('No se permite acceso directo al script');
class Mail {
	function sendMail($to, $from_name, $from_mail, $subject, $message)
	{
		require_once 'application/swift/swift_required.php';
		include_once 'application/config/url_login.php';
		include_once 'application/config/mail_server.php';

		if(!is_array($to)) $to = array($to);

		$error = '';
		//foreach ($to as $mail_usuario) {
			$msg = Swift_Message::newInstance();
			$msg->setSubject($subject);
			$msg->setFrom(array("$from_mail" => "$from_name"));
			//$msg->setTo(array($mail_usuario));
			$msg->setTo($to);
			$msg->setBody(
			'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
			<head>
				<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
			</head>
			<body bgcolor="#FFFFFF" style="font-family: Arial; font-size: 10pt; background-color: #FFFFFF;">
				<table width="600px" cellpadding="0" cellspacing="0" border="0" style="font-family: Arial; font-size: 10pt; width: 600px;">
					<tbody>
						<tr>
							<td>
								<table style="font-family: Arial; font-size: 10pt;border: 1px solid #CCC;" cellpadding="0" cellspacing="0">
									<tbody>
										<tr>
											<td width="20px" style="width: 20px; background-color: #FFFFFF;">&nbsp;</td>
											<td width="400px" height="60px" style="height: 60px; width: 400px; background-color: #FFFFFF;">
												<img src="' . $msg->embed(Swift_Image::fromPath(base_url() . "images/logo.png")) .  
												'" border="0" alt="" align="middle" style="vertical-align: middle;">
											</td>
											<td width="160px" align="right" style="background-color: #FFFFFF; width:160px;">
												<table style="font-family: Arial; font-size: 10pt;" cellpadding="0" cellspacing="0">
													<tbody>
													<tr>
														<td align="center" bgcolor="#84B736" height="33" style="display: block; border: 1px solid #666666; background-color: #84B736; border-radius: 4px;">
															<a href="' . $url_login . '" style="display: inline-block; text-decoration: none; font-family: Arial; font-weight: bold; color: #ffffff;font-size: 10pt;line-height: 33px;padding-left: 10px; padding-right: 10px;">Login</a>
														</td>
													</tr>
													</tbody>
												</table>
											</td>
											<td width="20px" style="width: 20px; background-color: #FFFFFF;">&nbsp;</td>
										</tr>
									</tbody>
								</table>
							</td>
						</tr>
					</tbody>
				</table>
				<br>
				<table style="font-family: Arial; font-size: 10pt;" cellpadding="2" cellspacing="0">
					<tbody>
					<tr>' .
						$message
						.
					'</tr>
					</tbody>
				</table>
				<br><br>
				<div style="font-family: Arial; font-size: 8pt;"><font face="Arial" size="1" color="#888888">This is an automatically generated email – please do not reply to it.</font></div>
			</body>
			</html>'
			, 'text/html');

			
			$smtp = Swift_SmtpTransport::newInstance($servidor, $puerto) 
			        ->setUsername($usuario) 
			        ->setPassword($password);
			$mailer = Swift_Mailer::newInstance($smtp);
			
			$exito = $mailer->send($msg);
			if(!$exito) $error .= "Message could not be sent to $mail_usuario.<br />";
		//}

		return $error;
	}
}
/* Fin del archivo */